# Darren
# 2025年02月18日20时41分55秒
import homework_module  # 导入模块


# 1题
def find(l_list):
    """
    有7个整数，有3个数出现了两次，1个数出现了一次，找出出现一次的那个数（异或^）
    :param l_list:
    :return:
    """
    # a ^ 0 = a ；a ^ a = 0(同0异1) 满足交换律，结合律
    # 出现两次，抵消为0
    result = 0
    for num in l_list:
        result ^= num
    return result


num_list = [1, 1, 2, 2, 3, 6, 6]
print(find(num_list))
# 2题
for i in range(20):
    print(i + 1, end=" ")
print("\n")


# 3题
def say_hello():
    """
    打印多次 hello
    :return:
    """
    print("hello1")
    print("hello2")
    print("hello3")


say_hello()

# 4题
if __name__ == '__main__':
    homework_module.print_line()

# 5题
list_1 = ['Darren', 'Steve', 'Bruce']
print(f"{list_1[0]}好帅！")
print("列表长度：%d" % len(list_1))
list_1.append("yue")
list_1.insert(1, "Mary")
print(list_1)
print("删除表尾：%s" % list_1.pop())
del list_1[1]
list_1.remove("Bruce")
print(list_1)
list_1[1] = "Grace"
print(list_1)
list_1.clear()
print(list_1)
list_2 = [y for x in range(4) for y in range(x)]
print(list_2)
list_2.reverse()
print("反转后：", list_2)
list_2.sort()
print("排序后：", list_2)
list_2.sort(reverse=True)
print("逆序排序后：", list_2)
print(f"{list_2}中0的个数:{list_2.count(0)}")
list_3 = [i for i in range(100) if i % 5 == 0]
print(list_3)
list_4 = [x if x % 10 != 0 else x // 5 for x in range(51)]
print(list_4)
list_5 = [[x * y for x in range(y + 1)] for y in range(5)]
print(list_5)

tuple_num = ("xiaoming", True, 2.85)
print(tuple_num.index(1))
str_1 = "{}的性别是{}，身高为{}".format(*tuple_num)
print(str_1)
list_5 = list(tuple_num)
print(list_5)
list_5.extend(list_4)
print(list_5)

dict_pet = {"Name": "Puppy",
            "Age": 3,
            "Size": "Small"}
dict_pet["Color"] = "Black"
dict_pet.setdefault("Name", "OP")
for k, v in dict_pet.items():
    print(k, v)
dict_pet.pop("Color")
del dict_pet["Age"]
print(len(dict_pet))
print(dict_pet)
print(dict_pet.get("Name"))
dict_cat = {"Hobby": "Jumping", "Owner": "Darren", "Name": "kitty"}
print(dict_pet)
dict_pet.update(dict_cat)
print(dict_pet)


def find2(my_list):
    """
    :param my_list:
    :return:
    """
    result = 0
    res1 = res2 = 0
    for num in my_list:
        result ^= num  # 结果是两个唯一的数的异或
    # 任何一个数与其相反数按位相与可得该数二进制表示中最右边的 1 所对应的数值
    split_flag = result & -result  # 取result某位为1对应的数
    # split_flag 值为1的位是异或的结果，说明两数在该位值不同->将列表的数分为两类
    # 分而治之，使用题1思想
    for i in my_list:
        if i & split_flag:
            res1 ^= i
        else:
            res2 ^= i
    return res1, res2


num_list = [1, 1, 2, 2, 3, 6, 6, 8, 3, 9, 8, 10]
res1, res2 = find2(num_list)
print(res1, res2)
